package com.jalarbee.stock.sales.dao.impl;

import com.jalarbee.core.bootik.client.business.Client;
import com.jalarbee.core.generic.dao.impl.GenericDaoJpa;
import com.jalarbee.core.user.business.User;
import com.jalarbee.core.util.Chunk;
import com.jalarbee.stock.category.business.Category;
import com.jalarbee.stock.product.business.Product;
import com.jalarbee.stock.sales.business.Sale;
import com.jalarbee.stock.sales.dao.SaleDao;
import java.util.List;
import javax.persistence.Query;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Abdoulaye <b>Ikhnaton</b> Diallo
 */
@Repository(value="saleDao")
public class SaleDaoJpa extends GenericDaoJpa<Sale, Long> implements SaleDao {

    @Override
    public List<Sale> getSales(Category category, Chunk chunk, boolean includeLineItems) {
        Query query = getEntityManager().createQuery("select s.* from Sale s where s.product.category=:category");
        query.setParameter("category", category);
        return query.getResultList();
    }

    @Override
    public List<Sale> getSales(Product product, Chunk chunk, boolean includeLineItems) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<Sale> getSales(Client customer, Chunk chunk, boolean includeLineItems) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<Sale> getSales(User salesperson, Chunk chunk, boolean includeLineItems) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<Sale> getSales() {
        Query query = getEntityManager().createQuery("select s from Sale s order by s.id desc");
        return query.getResultList();
    }

}
